//
//  LFBStartController.m
//  loveFreshBeen
//
//  Created by Feng on 2017/7/9.
//  Copyright © 2017年 feng. All rights reserved.
//

#import "LFBStartController.h"
#import "LFBStartFlowLayout.h"
#import "LFBStartModel.h"
#import "LFBStartCollectionViewCell.h"
#import "LFBTabBarController.h"

@interface LFBStartController () <UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,strong) NSMutableArray *imageArray;

@end

static NSString *CELL = @"CELL";

@implementation LFBStartController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setImageArrayData];
    
    [self setupUI];
}

- (void)setImageArrayData
{
    self.imageArray = [NSMutableArray array];
    for(NSInteger i = 1;i <= 4;i++)
    {
        LFBStartModel *model = [LFBStartModel new];
        model.imageName = [NSString stringWithFormat:@"guide_40_%zd",i];
        [self.imageArray addObject:model];
    }
}

- (void)setupUI
{
    LFBStartFlowLayout *flowLayout = [LFBStartFlowLayout new];
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:flowLayout];
    [self.view addSubview:collectionView];
    
    collectionView.dataSource = self;
    collectionView.delegate = self;
    
    [collectionView registerClass:[LFBStartCollectionViewCell class] forCellWithReuseIdentifier:CELL];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return  1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.imageArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LFBStartCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CELL forIndexPath:indexPath];
    
    cell.model = self.imageArray[indexPath.item];
    
    if(indexPath.item == 3)
    {
        cell.startButton.hidden = NO;
        cell.startButtonBlock = ^{
            
            LFBTabBarController *tabBarVC = [LFBTabBarController new];
            
            [self presentViewController:tabBarVC animated:NO completion:nil];
        };
    }
    else
    {
        cell.startButton.hidden = YES;
    }
    
    return cell;
}

@end
